<script setup>
import {
    Management,
    Promotion,
    UserFilled,
    User,
    Crop,
    EditPen,
    SwitchButton,
    CaretBottom
} from '@element-plus/icons-vue'

import { ref ,onMounted} from 'vue'
import { useRouter } from 'vue-router'
//axios
import request from "@/utils/request";
const router = useRouter()

const userqu = ref({});
//到首页获取当前用户信息
const userId = ref(0)
onMounted(()=>{
    request.get("/api/Home/Inquireiduser").then( (re) => {
        userId.value = re.data;

    })
})



const logout = () => {
  localStorage.removeItem('token')
  router.push('/login')
}
</script>

<template>
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            
            <el-menu active-text-color="rgb(119, 137, 247)" background-color="rgb(250, 238, 247)" text-color=router>
                <!-- 点击文字的时候展示哪个组件（index） -->
                <!-- <el-menu-item @click="$router.replace({ path: '/article/category' })">
                    <el-icon>
                        <Management />
                    </el-icon>
                    <span>宿管</span>
                </el-menu-item> -->
                <el-menu-item @click="$router.replace({ path: '/article/ArticleManage' })">
                    <el-icon>
                        <Promotion />
                    </el-icon>
                    <span>宿舍报修</span>
                </el-menu-item>

                <el-sub-menu index="1">
                    <template #title>
                        <el-icon>
                            <UserFilled />
                        </el-icon>
                        <span>房间管理</span>
                    </template>
                    <el-menu-item @click="$router.replace({ path: '/user/Userinfo' })">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>男生宿舍</span>
                    </el-menu-item>
                    <el-menu-item @click="$router.replace({ path: '/user/UserAvatar' })">
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>女生宿舍</span>
                    </el-menu-item>

                </el-sub-menu>

                <el-sub-menu index="2">
                    <template #title>
                        <el-icon>
                            <UserFilled />
                        </el-icon>
                        <span>个人中心</span>
                    </template>
                    <!-- 子菜单 -->
                    <!-- <el-menu-item>
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>基本资料</span>
                    </el-menu-item> -->
                    <!-- <el-menu-item>
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>更换头像</span>
                    </el-menu-item> -->
                    <el-menu-item @click="$router.replace({ path: '/user/UserResetPassword' })">
                        <el-icon>
                            <EditPen />
                        </el-icon>
                        <span>修改密码</span>
                    </el-menu-item>
                </el-sub-menu>
            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header>
                <div>用户<strong>{{ userId.username }}</strong></div>
                <!-- 下拉菜单 -->
                <el-dropdown placement="bottom-end">
                    <span class="el-dropdown__box">
                        <!-- 头像 -->
                        <el-avatar :src="avatar" />
                        <el-icon>
                            <CaretBottom />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <!-- <el-dropdown-item command="profile" :icon="User">基本资料</el-dropdown-item> -->
                            <!-- <el-dropdown-item command="avatar" :icon="Crop">更换头像</el-dropdown-item> -->
                            <el-dropdown-item command="password" :icon="EditPen" @click="$router.replace({ path: '/user/UserResetPassword' })">修改密码</el-dropdown-item>
                            <el-dropdown-item command="logout" :icon="SwitchButton" @click="logout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <!-- <div style="width: 1290px; height: 570px;border: 1px solid red;">
                    内容展示区
                </div> -->
                <!-- 菜单项设置路由属性，index里设置路径，表示这个区域的router-vue会展示哪个.vue的内容 -->

                <router-view></router-view>

            </el-main>
            <!-- 底部区域 -->
            <el-footer>广西民族大学 </el-footer>
        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;

    .el-aside {
        background-color: rgb(250, 238, 247);

        &__logo {
            height: 120px;
            background: url('@/assets/minda.png') no-repeat center / 120px auto;
        }

        .el-menu {
            border-right: none;
        }
    }

    .el-header {
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #999;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #666;
    }
}
</style>